home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.0 KB | 248 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFilRep.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWFILREP_H
- #define FWFILREP_H
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWCOUPTR_H
- #include "FWCouPtr.h"
- #endif
-
- #ifndef FWFILE_H
- #include "FWFileSy.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWACCBUF_H
- #include "FWAccBuf.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
- #include <windows.h>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // FW_CFileRep
- //
- // Class holding representation for FW_CFileSink. This is an implementation class
- // and should not be used in general. Use the FW_CFileSink class instead.
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CFileRep : public FW_CCountedPtrRep
- {
-
- public:
-
- enum
- {
- kDefaultBufferCapacity = 1024
- };
-
- FW_CFileRep(const FW_CFileSpecification& fileSpecification,
- long bufferSize = kDefaultBufferCapacity,
- FW_Boolean allowCreate = FALSE);
- // Open with exclusive access
-
- FW_CFileRep(const FW_CFileSpecification& fileSpecification,
- const FW_CAccessPermission& permission,
- long bufferSize = kDefaultBufferCapacity,
- FW_Boolean allowCreate = FALSE);
- // Open with specified permissions.
-
- virtual ~ FW_CFileRep();
- // Close the file.
-
-
- //===========================================================
- // Read/Write
- //===========================================================
-
- void Read(void * destination, long count);
- // Read 'count' bytes from current position to 'destination' and
- // increment current position by 'count'.
-
- const void* ReadPeek(long& availableReadBytes);
- // Return read-only pointer to 'availableReadBytes' bytes of data
- // at current file position.
-
- void ReadPeekAdvance(long bytesRead);
- // Advance position in ReadPeek() buffer by 'bytesRead' bytes.
-
- void Write(const void* source, long count);
- // Write 'count' bytes from 'source' to current file position.
-
- void* WritePeek(long& availableWriteBytes);
- // Return write-only pointer to 'availableWriteBytes' bytes of data
- // at current file position.
-
- void WritePeekAdvance(long bytesWritten);
- // Advance position in WritePeek() buffer by 'bytesWritten' bytes.
-
-
- //===========================================================
- // File Positioning
- //===========================================================
-
- long GetLength() const;
- // Return the logical size of the file.
-
- void SetLength(long length);
- // Return the logical size of the file.
-
- long GetPosition() const;
- // Return current file position.
-
- void SetPosition(FW_CFileSystem::MoveMethods positioningMode,
- long markOffset);
- // Set current file position using mode.
-
- long BytesToEndOfFile() const;
- // Returns the number of bytes from the current position to the
- // end of the file.
-
-
- //===========================================================
- // Accessor methods
- //===========================================================
-
- void GetPermissions(FW_CAccessPermission& thePerms) const;
- // Returns the permissions used to open this file.
-
- FW_CFileSpecification GetFileSpecification() const;
- // Returns a reference to the file. This routine is primarily used for
- // exception handling.
-
- FW_FileAccessHandle GetFileHandle() const;
- // Returns the native platform handle to the file.
-
-
- //===========================================================
- // Operators
- //===========================================================
-
- FW_Boolean operator==(const FW_CFileRep& theOtherFile) const;
- // Equality operator.
-
- FW_Boolean operator!=(const FW_CFileRep& theOtherFile) const;
- // Inequality operator.
-
-
- private:
- void PrivOpenFile(FW_Boolean allowCreate);
- // Open the file and prepare it for access.
-
- void PrivCloseFile();
- // Close the file and clear all references to it.
-
- void PrivDoRead(void * destination, long count);
- // Perform the actual reading of data.
-
- void PrivDoWrite(const void* source, long count);
- // Perform the actual writing of data.
-
- void FlushAndInvalidateBuffer();
- // Write pending "WritePeek" buffer if any.
- // Invalidate active "WritePeek" or "ReadPeek" buffer.
-
- FW_CFileRep(const FW_CFileRep& otherAccess);
- FW_CFileRep& operator=(const FW_CFileRep& theOtherFile);
- // Copy constructor and assignment operator not valid for this class.
-
- FW_CFileSpecification fFileSpec;
- FW_CAccessPermission fPermission;
- FW_FileAccessHandle fFileHandle;
- FW_CPrivFileAccessBuffer fFileBuffer;
-
- #ifdef FW_BUILD_WIN
- private:
- FW_CFileSystem::FileError PrivWinMoveFilePointer(long Offset,
- FW_CFileSystem::MoveMethods theMoveMethod,
- long& newPosition) const;
-
- static short PrivWinGetIOBufferSize(long bytesDesired,
- const void* buffer);
-
- static FW_CFileSystem::FileError PrivWinPrimitiveRead(FW_FileAccessHandle handle,
- short bytesToRead,
- void* buffer,
- short& bytesActuallyRead);
- static FW_CFileSystem::FileError PrivWinPrimitiveWrite(FW_FileAccessHandle handle,
- short bytesToWrite,
- const void* buffer,
- short& bytesActuallyWritten);
- #endif
- };
-
- //========================================================================================
- // CLASS FW_PFile
- //========================================================================================
-
- class FW_CLASS_ATTR FW_PFile : public FW_CCountedPtr
- {
- public:
- virtual ~ FW_PFile();
-
- enum
- {
- kDefaultBufferCapacity = FW_CFileRep::kDefaultBufferCapacity
- };
-
- FW_PFile(FW_CFileRep* privFileAccessRep);
-
- FW_PFile(const FW_CFileSpecification& fileSpecification,
- long bufferSize = kDefaultBufferCapacity,
- FW_Boolean allowCreate = FALSE);
- // Open with exclusive access
-
- FW_PFile(const FW_CFileSpecification& fileSpecification,
- const FW_CAccessPermission& permission,
- long bufferSize = kDefaultBufferCapacity,
- FW_Boolean allowCreate = FALSE);
- // Open with specified permissions.
-
- // ----- Overload of accessors methods -----
- FW_CFileRep* operator->() const;
- FW_CFileRep& operator*() const;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_PFile::operator->
- //----------------------------------------------------------------------------------------
-
- inline FW_CFileRep* FW_PFile::operator->() const
- {
- return (FW_CFileRep*)fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PFile::operator*
- //----------------------------------------------------------------------------------------
-
- inline FW_CFileRep& FW_PFile::operator*() const
- {
- return *((FW_CFileRep*)fRep);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-